﻿<Window xmlns:chartingToolkit="clr-namespace:System.Windows.Controls.DataVisualization.Charting;assembly=System.Windows.Controls.DataVisualization.Toolkit"  x:Class="AzureLogManager.LogBoard.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Log manager"
        Height="350"
        Width="600"
        MinHeight="350"
        MinWidth="600">
    <Window.Resources>
        <Style x:Key="GroupHeaderStyle"
               TargetType="{x:Type GroupItem}">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type GroupItem}">
                        <Expander>
                            <Expander.Header>
                                <TextBlock Text="{Binding Name}" />
                            </Expander.Header>
                            <ItemsPresenter />
                        </Expander>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </Window.Resources>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition />
        </Grid.RowDefinitions>

        <StackPanel Orientation="Horizontal">
            <DatePicker x:Name="btDatePicker"
                        Margin="5,5,10,5"
                        Padding="5" />
            <Button x:Name="btRefresh"
                    Content="Refresh"
                    Click="btRefresh_Click"
                    Margin="5,5,10,5"
                    Padding="5" />
            <TextBlock x:Name="txtCount"
                       Margin="5,5,10,5"
                       Padding="5" />
            <TextBlock x:Name="txtIPCount"
                       Margin="5,5,10,5"
                       Padding="5" />
        </StackPanel>

        <TabControl Grid.Row="1">
            <TabItem Header="Logs">
                <ScrollViewer>
                    <Grid>
                        <ProgressBar x:Name="pbarLogs"
                                     VerticalAlignment="Center"
                                     HorizontalAlignment="Center"
                                     IsIndeterminate="True"
                                     Width="100"
                                     Height="20" />

                        <DataGrid Name="dgLogs"
                                  IsReadOnly="True"
                                  Visibility="Collapsed"
                                  AutoGenerateColumns="False"
                                  RowDetailsVisibilityMode="VisibleWhenSelected"
                                  AlternatingRowBackground="LightGray"
                                  VerticalScrollBarVisibility="Auto">
                            <DataGrid.GroupStyle>
                                <GroupStyle ContainerStyle="{StaticResource GroupHeaderStyle}">
                                    <GroupStyle.Panel>
                                        <ItemsPanelTemplate>
                                            <DataGridRowsPresenter />
                                        </ItemsPanelTemplate>
                                    </GroupStyle.Panel>
                                </GroupStyle>
                            </DataGrid.GroupStyle>
                            <DataGrid.BindingGroup>
                                <BindingGroup />
                            </DataGrid.BindingGroup>
                            <DataGrid.Columns>
                                <DataGridTextColumn Header="Time"
                                                    Binding="{Binding Timestamp, StringFormat={}{0:yyyy-MM-dd HH:mm:ss}}"
                                                    Width="2*" />
                                <DataGridTextColumn Header="Duration"
                                                    Binding="{Binding Duration}"
                                                    Width="*" />
                                <DataGridTextColumn Header="Type"
                                                    Binding="{Binding Type}"
                                                    Width="*" />
                                <DataGridTextColumn Header="Message"
                                                    Binding="{Binding Message}"
                                                    Width="3*" />
                            </DataGrid.Columns>

                            <DataGrid.RowDetailsTemplate>
                                <DataTemplate>
                                    <Grid>
                                        <TextBlock TextWrapping="Wrap"
                                                   Text="{Binding Message}" />
                                    </Grid>
                                </DataTemplate>
                            </DataGrid.RowDetailsTemplate>
                        </DataGrid>
                    </Grid>
                </ScrollViewer>
            </TabItem>
            <TabItem Header="Stats">
                <Grid>
                    <ProgressBar x:Name="pbarStats"
                                 VerticalAlignment="Center"
                                 HorizontalAlignment="Center"
                                 IsIndeterminate="True"
                                 Width="100"
                                 Height="20" />

                    <TabControl x:Name="tabControlStats" Visibility="Collapsed">
                        <TabItem Header="Summary">
                            <Grid>
                                <chartingToolkit:Chart x:Name="chartStats">
                                    <chartingToolkit:ColumnSeries x:Name="colSeriesVisits" />
                                    <chartingToolkit:ColumnSeries x:Name="colSeriesIPs" />
                                    <chartingToolkit:LineSeries x:Name="lineSeriesUniqueIPs" />
                                </chartingToolkit:Chart>
                            </Grid>
                        </TabItem>
                        <TabItem Header="Details">
                            <DataGrid Name="dgStatsDetails"
                                      IsReadOnly="True"
                                      AutoGenerateColumns="False"
                                      AlternatingRowBackground="LightGray">
                                <DataGrid.Columns>
                                    <DataGridTextColumn Header="IP"
                                                        Binding="{Binding Key}"
                                                        Width="*" />
                                    <DataGridTextColumn Header="Visits"
                                                        Binding="{Binding Value}"
                                                        Width="*" />
                                </DataGrid.Columns>
                            </DataGrid>
                        </TabItem>
                    </TabControl>
                </Grid>
            </TabItem>
        </TabControl>
    </Grid>
</Window>